package com.cauli.manage.operationLog.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cauli.manage.operationLog.model.vo.OperationLogVO;
import com.cauli.manage.operationLog.model.dto.OperationLogQueryDTO;
import com.cauli.manage.operationLog.model.entity.OperationLog;
import com.cauli.manage.operationLog.service.OperationLogService;
import com.cauli.utils.util.ResultResponse;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author Cauli
 * @date 2023-03-28 12:00
 * @description 操作日志 前端控制器
 */
@Api(tags = "操作日志")
@ApiSort(4)
@RestController
@RequestMapping("/operationLog")
public class OperationLogController {
    @Autowired
    private OperationLogService operationLogService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取操作日志列表")
    @GetMapping("/list")
    public ResultResponse<OperationLog> listOperationLog(OperationLogQueryDTO operationLogQueryDTO) {
        Page<OperationLog> operationLogPage = operationLogService.getOperationLogPage(operationLogQueryDTO);
        return ResultResponse.success().dataList(operationLogPage.getRecords(), operationLogPage.getTotal());
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "根据操作日志ID获取详细信息")
    @GetMapping("/{operationLogId}")
    public ResultResponse<OperationLogVO> getOperationLog(@PathVariable(value = "operationLogId") Long operationLogId) {
        OperationLogVO operationLogVO = operationLogService.getOperationLogById(operationLogId);
        return ResultResponse.success().data(operationLogVO);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除操作日志")
    @DeleteMapping(value = "/{operationLogIds}")
    public ResultResponse<Void> deleteOperationLog(@PathVariable List<Long> operationLogIds) {
        operationLogService.deleteOperationLog(operationLogIds);
        return ResultResponse.success().message("删除成功");
    }
}
